//
//  ViewController.m
//  XLSphereView
//
//  Created by 袁小龙 on 16/4/4.
//  Copyright © 2016年 xiaolong. All rights reserved.
//

#import "ViewController.h"
#import "XLSphereView.h"
#import "LoLViewController.h"
#import "FilemViewController.h"
#import "CartoonViewController.h"
#import "SportsViewController.h"
#import "MusicViewController.h"
#import "PrefixHeader.pch"
@interface ViewController ()

@property (nonatomic,strong) XLSphereView *sphereView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //self.navigationItem.title = @"兴趣组";
    //self.title = @"兴趣组";
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0 , 100, 44)];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.font = [UIFont boldSystemFontOfSize:17];
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text = @"兴趣组";
    self.navigationItem.titleView = titleLabel;
    
    self.navigationController.navigationBar.barTintColor = themeColor;
    self.view.backgroundColor = [UIColor blackColor];
    CGFloat sphereViewW = self.view.frame.size.width - 30 * 2;
    CGFloat sphereViewH = sphereViewW;
    _sphereView = [[XLSphereView alloc] initWithFrame:CGRectMake(30, 100, sphereViewW, sphereViewH)];
    NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:0];
    for (NSInteger i = 0; i < 5; i ++) {
        //按钮尺寸
        UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 80, 80)];
        
        //按钮标题
        //[btn setTitle:[NSString stringWithFormat:@"XL%ld", i] forState:UIControlStateNormal];
        
        //按钮背景
        [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%ld.png",i+1]] forState:UIControlStateNormal];
        //按钮背景色ß®
        btn.backgroundColor = [UIColor colorWithRed:arc4random_uniform(255)/255. green:arc4random_uniform(255)/255. blue:arc4random_uniform(255)/255. alpha:1.];
        //按钮标题色
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        //按钮标题字体大小
        btn.titleLabel.font = [UIFont systemFontOfSize:24.];
        btn.tag = 100 + i;
        //圆角
        btn.layer.cornerRadius = 40;
        btn.clipsToBounds = YES;
        [btn addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
        [array addObject:btn];
        [_sphereView addSubview:btn];
    }
    [_sphereView setItems:array];
    [self.view addSubview:_sphereView];
    
}

- (void)buttonPressed:(UIButton *)btn
{
    [_sphereView timerStop];
    
    [UIView animateWithDuration:0.3 animations:^{
        btn.transform = CGAffineTransformMakeScale(2., 2.);
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.3 animations:^{
            btn.transform = CGAffineTransformMakeScale(1., 1.);
        } completion:^(BOOL finished) {
            [_sphereView timerStart];
        }];
    }];
    //点击事件
    if (btn.tag == 100) {
        LoLViewController *lolVc = [[LoLViewController alloc] init];
        [self.navigationController pushViewController:lolVc animated:YES];
    }else if (btn.tag == 101){
        FilemViewController *filemVc = [[FilemViewController alloc] init];
        [self.navigationController pushViewController:filemVc animated:YES];
    }else if (btn.tag == 102){
        CartoonViewController *cartoonVc = [[CartoonViewController alloc] init];
        [self.navigationController pushViewController:cartoonVc animated:YES];
    }else if (btn.tag == 103){
        SportsViewController *sportsVc = [[SportsViewController alloc] init];
        [self.navigationController pushViewController:sportsVc animated:YES];
    }else if (btn.tag == 104){
        MusicViewController *musicVc = [[MusicViewController alloc] init];
        [self.navigationController pushViewController:musicVc animated:YES];
    }
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
